<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta name="description" content="">
    <meta http-equiv="x-dns-prefetch-control" content="on">

    <title>费用明细</title>
    <link href="../../css/css.css" rel="stylesheet" type="text/css">
    <script src="../../js/jquery-v1.11.2.min.js"></script>
    <script src="../../js/common.js"></script>
    <script src="../../js/customer.js"></script>
</head>
<body>
<div id="priceDiv">
</div>

<input type="hidden" name="waybillId" id="waybillId"/>
<input type="hidden" id="paymentType" name="paymentType" value="10" />
</body>
<script>
    function setupWebViewJavascriptBridge(callback) {
        if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
        if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
        window.WVJBCallbacks = [callback];
        var WVJBIframe = document.createElement('iframe');
        WVJBIframe.style.display = 'none';
        WVJBIframe.src = 'https://__bridge_loaded__';
        document.documentElement.appendChild(WVJBIframe);
        setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
    }

    $(function () {
        //token验证
        checkToken();
    });
    $(function () {
        var LocString = String(window.document.location.href);
        var waybillId = GetArgsFromHref("waybillId");
        var paymentType = GetArgsFromHref("paymentType");
        if(!paymentType)paymentType="10";
        //'customerUuid':customerUuid
        var customerUuid = getCookie("customerUuid")
        var url = _global.serverHost + "/consignerOrderManger/orderFeeDetail.htm";
        var data = {
            'waybillId': waybillId,
            "paymentType": paymentType,
            'customerUuid': customerUuid
        };
        _callAjaxRequest(url, data, callBack);

        function callBack(data) {

            var priceDivhtml = '';


            var waybill = data.waybill;

            var distance = '';
            var startFee = '';
            var exceedFee = '';
            var exceedDistance = 0;
            
            var planLoadFee=waybill.planLoadFee;
            var planUnloadFee=waybill.planUnloadFee;
            var planLowSpeedFee=waybill.planLowSpeedFee;
            var ln_planWaitTime=waybill.planLoadTime-10+waybill.planUnloadTime+waybill.planLowSpeedTime;
            
            var loadFee=waybill.loadFee;
            var unloadFee=waybill.unloadFee;
            var lowSpeedFee=waybill.lowSpeedFee;
            var ln_waitTime=waybill.unloadTime+waybill.lowSpeedTime;
            if(waybill.loadTime>600){//超过10分钟=600秒
            	ln_waitTime=ln_waitTime+waybill.loadTime-600;
            }
            var showLoadAndUnloadFee=0;
            var showLowSpeedFee=0;
           
            if ( waybill.status*1<40) {
                distance = waybill.planDistance;
                showLoadAndUnloadFee=planLoadFee*1+planUnloadFee*1;
                showLowSpeedFee=planLowSpeedFee;
                ln_waitTime=ln_planWaitTime*60;
            } else {
            	ln_waitTime=ln_waitTime;
                if(waybill.distance == undefined ){
                	distance = 0;
                }else{
                	distance = waybill.distance;
                }
                showLoadAndUnloadFee=loadFee*1+unloadFee*1;
                showLowSpeedFee=lowSpeedFee;
            }
            if(parseInt(distance)>=3){
            	exceedDistance=(distance-3);
            	exceedDistance=exceedDistance.toFixed(1);
            }
            if (  waybill.status*1<40) {
                startFee = waybill.planStartFee;
            } else {
            	if(waybill.startFee == undefined){
            		 startFee =0;
            	}else{
            		 startFee = waybill.startFee;
            	}
               
            }
            if (waybill.status*1<40) {
                exceedFee = waybill.planExceedFee;
            } else {
            	if(waybill.exceedFee==undefined){
            		exceedFee = 0;
            	}else{
            		exceedFee = waybill.exceedFee;
            	}
                
            }
            priceDivhtml = priceDivhtml + '<section class="tabbtnarea">'
                    + ' <li class="w33 rline" onclick="goDetail(' + waybill.waybillId + ')">订单信息</li>'
                    + '  <li class="w33 rline" onclick="goWaybillTrack(' + waybill.waybillId + ')">订单轨迹</li>'
                    + '<li class="w33"><span class="tabfouse">费用明细</span></li>'
                    + '</section>';
            priceDivhtml = priceDivhtml + '<section class="itemgroup mt44 p15">'
                    + '<div class="oneitem">'
                    + '<div class="gray left">总计行驶:</div>'
                    + '<div class="right"><label class="mr5">' + distance + '</label>公里</div>'
                    + ' </div>';
            priceDivhtml = priceDivhtml + ' <div class="oneitem">'
                    + '<div class="gray left">起步价(含3公里内):</div>'
                    + '<div class="right"><label class="red mr5">' + startFee + '</label>元</div>'
                    + ' </div>';
            priceDivhtml = priceDivhtml + '  <div class="oneitem" style="display:none;">'
                    + '<div class="gray left">超里程费(超出'+exceedDistance+'公里):</div>'
                    + '<div class="right"><label class="red mr5">' + exceedFee + '</label>元</div>'
                    + '</div>';
            priceDivhtml = priceDivhtml + '  <div class="oneitem">'
                    + '<div class="gray left">运价:</div>'
                    + '<div class="right"><label class="red mr5">' + data.vehiclePrice.pv3 + '</label>元/公里</div>'
                    + '</div>';
            if(waybill.placeDate){
            	priceDivhtml = priceDivhtml + '  <div class="oneitem">'
                    + '<div class="gray left">起运时间:</div>'
                    + '<div class="right"><label class="mr5">' + waybill.placeDate + '</label></div>'
                    + '</div>';
            }else{
            	priceDivhtml = priceDivhtml + '  <div class="oneitem">'
                + '<div class="gray left">起运时间:</div>'
                + '<div class="right"><label class="mr5">--</label></div>'
                + '</div>';
            }
            if(waybill.unloadDate){
                    priceDivhtml = priceDivhtml + '  <div class="oneitem">'
                    + '<div class="gray left">到达时间:</div>'
                    + '<div class="right"><label class="mr5">' + waybill.unloadDate + '</label></div>'
                    + '</div>';
            }else{
            	priceDivhtml = priceDivhtml + '  <div class="oneitem">'
                + '<div class="gray left">到达时间:</div>'
                + '<div class="right"><label class="mr5">--</label></div>'
                + '</div>';
            }
            priceDivhtml = priceDivhtml + '  <div class="oneitem">'
                    + '<div class="gray left">等候时间:</div>'
                    + '<div class="right"><label class="mr5">' + Number(ln_waitTime).formatTime() + '</label></div>'
                    + '</div>';
            priceDivhtml = priceDivhtml + '<div class="oneitem" style="display:none;">'
                    + '<div class="gray left">装/卸货等待费用:</div>'
                    + '<div class="right"><label class="red mr5">' + showLoadAndUnloadFee + '</label>元</div>'
                    + '</div>';
        
            priceDivhtml = priceDivhtml + '<div class="oneitem" style="display:none;">'
                    + '<div class="gray left">行驶途中等待费用:</div>'
                    + '<div class="right"><label class="red mr5">' + showLowSpeedFee + '</label>元</div>'
                    + '</div>';
            var requireList = data.requireList;
            if (requireList != null && requireList.length > 0) {
                for (var i = 0; i < requireList.length; i++) {
                    priceDivhtml = priceDivhtml + '<div class="oneitem">'
                            + ' <div class="gray left">特殊需求(' + requireList[i].requirementName + '):</div>'
                            + ' <div class="right"><label class="red mr5">' + requireList[i].feeAmout + '</label>元</div>'
                            + '</div>';
                }
            }
            if(waybill.hignRoadFee){
	            priceDivhtml = priceDivhtml + '<div class="oneitem">'
	            + '<div class="gray left">路桥费:</div>'
	            + '<div class="right"><label class="red mr5">' + waybill.hignRoadFee + '</label>元</div>'
	            + '</div>';
            }
            
            var paymentTypeName = data.paymentTypeName;
            priceDivhtml = priceDivhtml + '</section>';
            priceDivhtml = priceDivhtml + '<section class="itemgroup mt10 p15">'
                    + '<div class="oneitem" onclick="changePay(' + waybill.waybillId + ')">'
                    + ' <div class="gray left">支付方式</div>'
                    + '<i class="iconfont rightsmallicon">&#xe6db;</i>'
                    + '<div class="right">' + paymentTypeName + '</div>'

                    + '</div>';


            priceDivhtml = priceDivhtml + '</section>';
            $("#paymentType").val(data.paymentType);
            priceDivhtml = priceDivhtml + '<section class="detialbottom">';
            if (waybill.status == '70') {
                priceDivhtml = priceDivhtml + '<button class="right btn addcert_det" onclick="javascript:waybillPay();">立即支付</button>';
            }
            var totalFee = waybill.totalFee;
            if (waybill.status*1<40) {
                totalFee = waybill.planTotalFee;
            }else{
            	if(totalFee == undefined ){
            		totalFee=0;
            	}
            	
            }
            priceDivhtml = priceDivhtml + ' <div class="cart_clear2 ml15">'
                    + ' <span class="font12">总费用:</span>'
                    + ' <span class="red font16">￥' + totalFee + '</span>'
                    + ' </div>'
                    + ' </section>';

            $("#priceDiv").html(priceDivhtml);

        }
    });
    function waybillPay() {
        var v_paymentType = GetArgsFromHref("paymentType");
        var v_waybillId = GetArgsFromHref("waybillId");
        if(!v_paymentType){
        	v_paymentType="10";
        }
        if (v_paymentType == "20") {//支付宝支付
            $.ajax({
                url: _global.serverHost + '/alipay/app_pay.htm',// 跳转到 action
                data: {waybillId: v_waybillId},
                type: 'post',
                cache: false,
                dataType: 'json',
                success: function (data) {
                    //返回的数据为一个form表单和提交该form的script,通过提交该表单（提交到支付宝，提交的数据等一系列内容已经全部包含在后台返回的data数据中，我们只需要运行data中的script即可）
                    if (data.code == 1) {
//		            document.body.innerHTML = data.data;
//		            //通过innerHTML添加的script代码不会自动执行，需要我们手动来执行
//		            var scripts = document.body.getElementsByTagName("script");
//		             for(var i=0;i<scripts.length;i++){ //一段一段执行script
//		                eval(scripts[i].innerHTML);
//		             }
                   setupWebViewJavascriptBridge(function(bridge) {
                                                
                                                
bridge.registerHandler('finishPhonePay_ali', function(data, responseCallback) {
                   
                   if (data.result == 1) {
                       var v_waybillId = GetArgsFromHref("waybillId");
                       var v_paymentType = GetArgsFromHref("paymentType");
                   if(!v_paymentType){
                       v_paymentType="10";//微信支付
                   }
                   var urlStr=_global.serverHost + '/alipay/app_pay_success_return.htm';// 跳转到 action
                   if(v_paymentType=="10"){
                       urlStr=_global.serverHost + '/wxpay/app_pay_success_return.htm';// 跳转到 action
                   }
                   $.ajax({
                          url: urlStr,
                          data: {waybillId: v_waybillId},
                          type: 'post',
                          cache: false,
                          dataType: 'json',
                          success: function (data) {
                          window.location.href = "../../customer/order/order_ok.html?waybillId=" + v_waybillId;
                          },
                          error: function () {
                          alert("支付发生异常，请重试！");
                          }
                          });
                   //跳转到成功页面
                   } else {
                   alert(data.message);
                   //处理错误信息
                   }
                   
                   
                   
                   });
                                                
                                                
                                                
                                                
                                                
                                                bridge.callHandler('startPhonePay', data, function responseCallback(responseData) {
                                                                   });
                                                });
                        //delegate.startPhonePay(data.type, data.money, data.out_trade_no);

                    } else {
                        alert("支付没有成功：" + data.msg);
                    }
                },
                error: function () {
                    alert("支付发生异常，请重试！");
                }
            });
        }else if(v_paymentType == "10") {//微信支付
        	$.ajax({
                url: _global.serverHost + '/wxpay/apppay.htm',// 跳转到 action
                data: {waybillId: v_waybillId},
                type: 'post',
                cache: false,
                dataType: 'json',
                success: function (data) {
                    //返回的数据为一个form表单和提交该form的script,通过提交该表单（提交到支付宝，提交的数据等一系列内容已经全部包含在后台返回的data数据中，我们只需要运行data中的script即可）
                    if (data.code == 1) {
                    	//点击“立即支付”，到达左图中步骤7之后，调用Native定义的JS方法startWeiChatPay(nonce_str,sign,prepayid)
                    	//随机字符串          nonce_str,签名                sign,预支付交易会话ID    prepayid"
                        //delegate.startWeiChatPay(data.nonce_str,data.sign,data.prepayid);
                   
                   setupWebViewJavascriptBridge(function(bridge) {
                                                
                                                
bridge.registerHandler('finishPhonePay', function(data, responseCallback) {
                       
                       
                       if (data.result == 1) {
                       var v_waybillId = GetArgsFromHref("waybillId");
                       var v_paymentType = GetArgsFromHref("paymentType");
                       if(!v_paymentType){
                       v_paymentType="10";//微信支付
                       }
                       var urlStr=_global.serverHost + '/alipay/app_pay_success_return.htm';// 跳转到 action
                       if(v_paymentType=="10"){
                       urlStr=_global.serverHost + '/wxpay/app_pay_success_return.htm';// 跳转到 action
                       }
                       $.ajax({
                              url: urlStr,
                              data: {waybillId: v_waybillId},
                              type: 'post',
                              cache: false,
                              dataType: 'json',
                              success: function (data) {
                              window.location.href = "../../customer/order/order_ok.html?waybillId=" + v_waybillId;
                              },
                              error: function () {
                              alert("支付发生异常，请重试！");
                              }
                              });
                       //跳转到成功页面
                       } else {
                       alert(data.message);
                       //处理错误信息
                       }
                       
                       
                       
                       });
                                                
                                                
                                                
                                                
                                                
                                                
                                                bridge.callHandler('startWeiChatPay', data, function responseCallback(responseData) {
                                                                   });
                    });
                   
                    } else {
                        alert("支付没有成功：" + data.msg);
                    }
                },
                error: function () {
                    alert("支付发生异常，请重试！");
                }
            });
        }else if(v_paymentType == "80") {//现金支付
        	$.ajax({
                url: _global.serverHost + '/wxpay/cashpay.htm',// 跳转到 action
                data: {waybillId: v_waybillId},
                type: 'post',
                cache: false,
                dataType: 'json',
                success: function (data) {
                    //返回的数据为一个form表单和提交该form的script,通过提交该表单（提交到支付宝，提交的数据等一系列内容已经全部包含在后台返回的data数据中，我们只需要运行data中的script即可）
                    if (data.code == 1) {
                    	//点击“立即支付”，到达左图中步骤7之后，调用Native定义的JS方法startWeiChatPay(nonce_str,sign,prepayid)
                    	//随机字符串          nonce_str,签名                sign,预支付交易会话ID    prepayid"
                        window.location.href = "../../customer/order/order_ok.html?waybillId=" + v_waybillId;
                    } else {
                        alert("支付没有成功：" + data.msg);
                    }
                },
                error: function () {
                    alert("支付发生异常，请重试！");
                }
            });
        }
    }

    //供app支付回调
    window.finishPhonePay = function (out_trade_no, result, message) {
        if (result == 1) {
            var v_waybillId = GetArgsFromHref("waybillId");
            var v_paymentType = GetArgsFromHref("paymentType");
            if(!v_paymentType){
            	v_paymentType="10";//微信支付
            }
            var urlStr=_global.serverHost + '/alipay/app_pay_success_return.htm';// 跳转到 action
            if(v_paymentType=="10"){
            	urlStr=_global.serverHost + '/wxpay/app_pay_success_return.htm';// 跳转到 action
            }
            $.ajax({
                url: urlStr,
                data: {waybillId: v_waybillId},
                type: 'post',
                cache: false,
                dataType: 'json',
                success: function (data) {
                    window.location.href = "../../customer/order/order_ok.html?waybillId=" + v_waybillId;
                },
                error: function () {
                    alert("支付发生异常，请重试！");
                }
            });
            //跳转到成功页面
        } else {
            alert(message);
            //处理错误信息
        }
    };

    function changePay(waybillId) {
        var paymentType = $("#paymentType").val();
        // window.location.href="${pageContext.request.contextPath}/consignerOrderManger/selectPay.htm?paymentType=${paymentType}&waybillId="+waybillId;
        window.location.href = "../../customer/order/select_pay.html?waybillId=" + waybillId + "&paymentType=" + paymentType;
    }
    function goDetail(waybillId) {
        //详情页面
        //window.location.href= _global.serverHost +"/consignerOrderManger/orderOkDetail.htm?waybillId="+waybillId;
        window.location.href = "../../customer/order/order_detail.html?waybillId=" + waybillId;
    }

    //运单轨迹
    function goWaybillTrack(waybillId) {
        // window.location.href="${pageContext.request.contextPath}/consignerOrderManger/orderTrack.htm?waybillId="+waybillId;
        window.location.href = "../../customer/order/order_trace.html?waybillId=" + waybillId;
    }
</script>
</html>
